/*
 * BodyPart.cpp
 *
 *  Created on: 10.10.2012
 *      Author: caffeine
 */



#include "../../FileLoader.h"
#include <log/Log.h>
#include "BodyPart.h"

void BodyPart::on_model_load(irr::scene::ISceneNode*parent){
	if (fileName=="")
		return;
	LOG("Try load %s",fileName.c_str());
	node=FileLoader::getModel(fileName,parent);
	//node=device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh(fileName),parent);
	node->grab();
}

void BodyPart::on_model_unload(){
	if (!node || fileName=="")
		return;
	node->remove();
	node->drop();
	node=0;
}

void BodyPart::setFileName(irr::io::path fn){
	if (fileName==fn)
		return;
	if (isLoaded()){
		unload();
		fileName=fn;
		load();
	}else
		fileName=fn;
}

BodyPart::BodyPart(irr::object::ContainerNodeObject*container,irr::IrrlichtDevice*d):irr::object::AnimattedModelObject(container,0,d),irr::ILoadableObject(d){
	device=d;
	fileName="";
	node=0;
}

BodyPart::~BodyPart(){
}

void BodyPart::on_setCurrentAnimation(irr::animation::IAnimationRecord*record){
	if (node)
		record->useFor(node);
}

void BodyPart::on_setAnimationGroup(irr::animation::IAnimation*group){
	if (node)
		group->useAnimation(node);
}

irr::scene::IAnimatedMeshSceneNode*BodyPart::getAnimationModel(){
	return node;
}
